<div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <%- message %>
</div>
<a class="btn btn-info" href="/articlec">返回分类</a>
<div class="panel panel-info">
<div class="panel-heading"><h4 class="panel-title">文章管理</h4></div>

<form action="/article/upsert/<%=_id?_id:'nil'%>" method="post" class="form-horizontal" id="uform" role="form">
     <%- hidden_field_tag("createDate", new Date().getTime())%>
    <div class="form-group">
        <label class="col-sm-2 control-label">所属分类</label>
        <div class="col-sm-8">

            <input name="articlec[name]" class="form-control" type="text" readonly>
            <input name="articlec[id]" type="hidden">
            <input name="articlec[area]" type="hidden">
            <input name="area" type="hidden">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">新闻标题</label>
        <div class="col-sm-8">

            <input name="name" class="form-control" type="text" >

        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">发布时间[默认当天]</label>
        <div class="col-sm-8">

          <div class="input-group date">
            <input type="text" class="form-control" readonly>
              <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
        </div>

        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">作者</label>
        <div class="col-sm-8">
            <input name="author" class="form-control" type="text">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">摘要</label>
        <div class="col-sm-8">
            <textarea name="digest" class="form-control" ></textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">图片轮播</label>
        <div class="col-sm-8">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="loopimage" value="true"> 图片是否轮播显示
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">相关图片</label>
        <div class="col-sm-8">
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
                开始上传
            </button>
            <div id="imageshow"></div>
        </div>
    </div>
    <div class="form-group">
        <label for="content" class="col-sm-2 control-label">文章内容</label>

        <div class="col-lg-10">
            <textarea name="content" id="content" rows="10" cols="80">

            </textarea>

        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">保存</button>
        </div>
    </div>

</form>
</div>
<script id="imagetpl" type="text/html">

  <( for(i = 0; i < list.length; i++) { )>

    <label id="image_item_<(=i)>" style="width:105px;height:105px;text-align:center">

      <img src="<(=list[i])>" style="width:100px;height:100px;">
      <input type="checkbox" name="imagelist[<(=i)>]" value="<(=list[i])>" checked>启用
    </label>

 <(})>

</script>


 <script>
     var beans = <%-beans%>;
     var state = <%=state%>||0;
     //console.log(beans);
     $(function(){

         if(state==1){
             //console.log(beans);
             location.href='/articlec?id='+beans['articlec']['id'];
             return ;
         }

         CKEDITOR.replace( 'content' ,{
             filebrowserImageUploadUrl: '/images/upload'
         } );
         $("form#uform").helpform(
                 {
                     'beans':beans,
                     'images':{
                         'show':'#imageshow',
                         'field':'imagelist',
                         'tempId':'imagetpl'

                     }
                 }
         );
         $('#fileupload').fileupload({
             dataType: 'json',
             done: function (e, jdata) {

                 var data = {};
                 var list =  [];
                 list.push(jdata.result.path);
                 data.list = list;
                 log(data);
                 var html = template.render('imagetpl', data);
                 $("#imageshow").append(html);
             },
             fail: function (e, data) {
                 notify('file upload size exceed limit of 126353');
             }
         });

         $('.input-group.date').datepicker({
             format: "yyyy-mm-dd",
             todayBtn: "linked",
             language: "zh-CN"
         }).on("changeDate",function(event){
             var rst = event.date?event.date.getTime():new Date().getTime();
             $("#createDate").val(rst);
         });

     });

 </script>

